
(function(window,document,Laya){
	var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;

	var GrahamScan=laya.maths.GrahamScan,Node=laya.display.Node,Rectangle=laya.maths.Rectangle,Sprite=laya.display.Sprite;
	/**
	*
	*@author ww
	*@version 1.0
	*
	*@created 2015-10-23 下午2:24:04
	*/
	//class debugviewkit.servertools.ClassTool
	var ClassTool=(function(){
		function ClassTool(){}
		__class(ClassTool,'debugviewkit.servertools.ClassTool');
		ClassTool.defineProperty=function(obj,name,des){
			/*__JS__ */Object.defineProperty(obj,name,des);;
		}

		ClassTool.getOwnPropertyDescriptor=function(obj,name){
			var rst;
			/*__JS__ */rst=Object.getOwnPropertyDescriptor(obj,name);;
			return rst;
		}

		ClassTool.getOwnPropertyDescriptors=function(obj){
			var rst;
			/*__JS__ */rst=Object.getOwnPropertyDescriptors(obj);;
			return rst;
		}

		ClassTool.getOwnPropertyNames=function(obj){
			var rst;
			/*__JS__ */rst=Object.getOwnPropertyNames(obj);;
			return rst;
		}

		ClassTool.getObjectGetSetKeys=function(obj,rst){
			if (!rst)rst=[];
			var keys;
			keys=debugviewkit.servertools.ClassTool.getOwnPropertyNames(obj);
			var key;
			for (key in keys){
				key=keys[key];
				if (key.indexOf("_$get_")>=0){
					key=key.replace("_$get_","");
					rst.push(key);
				}
			}
			if (obj["__proto__"]){
				ClassTool.getObjectGetSetKeys(obj["__proto__"],rst);
			}
			return rst;
		}

		ClassTool.getNoSameArr=function(arr){
			var i=0,len=0;
			var rst;
			rst=[];
			var tItem;
			len=arr.length;
			for (i=0;i < len;i++){
				tItem=arr[i];
				if (rst.indexOf(tItem)< 0){
					rst.push(tItem);
				}
			}
			return rst;
		}

		ClassTool.getObjectDisplayAbleKeys=function(obj,rst){
			if (!rst)rst=[];
			var key;
			var tValue;
			var tType;
			for (key in obj){
				tValue=obj[key];
				tType=typeof(tValue);
				if (key.charAt(0)=="_")continue ;
				rst.push(key);
			}
			ClassTool.getObjectGetSetKeys(obj,rst);
			rst=ClassTool.getNoSameArr(rst);
			return rst;
		}

		ClassTool.getClassName=function(tar){
			if ((typeof tar=='function'))return tar.name;
			return tar["constructor"].name;
		}

		ClassTool.getNodeClassAndName=function(tar){
			if (!tar)return "null";
			var rst;
			if (tar.name){
				rst=ClassTool.getClassName(tar)+"("+tar.name+")";
				}else{
				rst=ClassTool.getClassName(tar);
			}
			return rst;
		}

		ClassTool.getClassNameByClz=function(clz){
			return clz["name"];
		}

		ClassTool.getClassByName=function(className){
			var rst;
			rst=Laya._runScript(className);
			return rst;
		}

		ClassTool.createObjByName=function(className){
			var clz;
			clz=ClassTool.getClassByName(className);
			return new clz();
		}

		__static(ClassTool,
		['displayTypes',function(){return this.displayTypes={"boolean":true,"number":true,"string":true };}
		]);
		return ClassTool;
	})()


	/**
	*...
	*@author ww
	*/
	//class debugviewkit.servertools.DisTool
	var DisTool=(function(){
		function DisTool(){}
		__class(DisTool,'debugviewkit.servertools.DisTool');
		DisTool.walkArr=function(arr,fun,_this){
			if(!arr)return;
			var i=0;
			var len=0;
			len=arr.length;
			for(i=0;i<len;i++){
				fun.apply(_this,[arr[i],i]);
			}
		}

		DisTool.showDisBoundToSprite=function(sprite,graphicSprite,color,lineWidth){
			(color===void 0)&& (color="#ff0000");
			(lineWidth===void 0)&& (lineWidth=1);
			var pointList;
			pointList=sprite._getBoundPointsM(true);
			if (!pointList || pointList.length < 1)
				return;
			pointList=GrahamScan.pListToPointList(pointList,true);
			DisTool.walkArr(pointList,sprite.localToGlobal,sprite);
			pointList=GrahamScan.pointListToPlist(pointList);
			DisTool._disBoundRec=Rectangle._getWrapRec(pointList,DisTool._disBoundRec);
			graphicSprite.graphics.drawRect(DisTool._disBoundRec.x,DisTool._disBoundRec.y,DisTool._disBoundRec.width,DisTool._disBoundRec.height,null,color,lineWidth);
		}

		DisTool.clearDebugLayer=function(){
			if (DisTool.debugLayer&&DisTool.debugLayer.graphics)
				DisTool.debugLayer.graphics.clear();
		}

		DisTool._initDebugLayer=function(){
			if (!DisTool.debugLayer){
				DisTool.debugLayer=new Sprite();
				DisTool.debugLayer.zOrder=99999;
				Laya.stage.addChild(DisTool.debugLayer);
			}
		}

		DisTool.showDisBounds=function(sprite){
			DisTool.clearDebugLayer();
			DisTool._initDebugLayer();
			if (! (sprite instanceof laya.display.Sprite ))return;
			var pointList;
			pointList=sprite._getBoundPointsM(true);
			if (!pointList || pointList.length < 1)
				return;
			pointList=GrahamScan.pListToPointList(pointList,true);
			DisTool.walkArr(pointList,sprite.localToGlobal,sprite);
			pointList=GrahamScan.pointListToPlist(pointList);
			DisTool._disBoundRec=Rectangle._getWrapRec(pointList,DisTool._disBoundRec);
			DisTool.debugLayer.graphics.drawRect(DisTool._disBoundRec.x,DisTool._disBoundRec.y,DisTool._disBoundRec.width,DisTool._disBoundRec.height,null,"#ff0000");
		}

		DisTool._disBoundRec=null
		DisTool.debugLayer=null
		return DisTool;
	})()


	/**
	*
	*@author ww
	*@version 1.0
	*
	*@created 2015-10-29 上午9:45:33
	*/
	//class debugviewkit.servertools.IDTools
	var IDTools=(function(){
		function IDTools(){
			this.tID=1;
		}

		__class(IDTools,'debugviewkit.servertools.IDTools');
		var __proto=IDTools.prototype;
		__proto.getID=function(){
			return this.tID++;
		}

		IDTools.getAID=function(){
			return IDTools._ID.getID();
		}

		IDTools.idObjE=function(obj,sign){
			(sign===void 0)&& (sign="default");
			if (obj["_M_id_"])return obj;
			if(!sign){
				sign="default";
			}
			if(!IDTools._idDic[sign]){
				IDTools._idDic[sign]=new IDTools();
			}
			obj["_M_id_"]=IDTools._idDic[sign].getAID();
			return obj;
		}

		IDTools.setObjID=function(obj,id){
			obj["_M_id_"]=id;
			return obj;
		}

		IDTools.idObj=function(obj){
			if (obj["_M_id_"])return obj;
			obj["_M_id_"]=IDTools.getAID();
			return obj;
		}

		IDTools.getObjID=function(obj){
			if(!obj)return-1;
			return obj["_M_id_"];
		}

		IDTools.getObjIDAuto=function(obj){
			if (!obj)return-1;
			IDTools.idObj(obj);
			return obj["_M_id_"];
		}

		IDTools.idSign="_M_id_";
		__static(IDTools,
		['_ID',function(){return this._ID=new IDTools();},'_idDic',function(){return this._idDic={"default":new IDTools()};}
		]);
		return IDTools;
	})()


	/**
	*...
	*@author ww
	*/
	//class debugviewkit.servertools.IPCServer
	var IPCServer=(function(){
		function IPCServer(){
			this.ipcRenderer=null;
			this.init();
		}

		__class(IPCServer,'debugviewkit.servertools.IPCServer');
		var __proto=IPCServer.prototype;
		__proto.init=function(){
			console.log("IPCServer Init");
			var electron;
			electron=/*__JS__ */require('electron');
			this.ipcRenderer=electron.ipcRenderer;
			this.ipcRenderer.on("message",this.onMessage.bind(this));
		}

		__proto.onMessage=function(sender,dataO){
			console.log("IPCServer message:",dataO);
			if (!dataO)return;
			var data;
			data=dataO.data;
			switch(dataO.type){
				case "getTree":
					this.sendMessage("Tree",RemoteWorkUtils.getTree());
					break ;
				case "getObjectData":
					this.sendMessage("ObjectData",RemoteWorkUtils.getObjectDataByDataO(dataO.data));
					break ;
				case "changeObjectValue":
					RemoteWorkUtils.changeObjectValue(data.compId,data.key,data.value);
					break ;
				case "showObjectBounds":
					RemoteWorkUtils.showTargetBounds(data.compId);
					break ;
				}
		}

		__proto.sendMessage=function(type,dataO){
			var paramO;
			paramO={};
			paramO.type=type;
			paramO.data=dataO;
			this.ipcRenderer.sendToHost("message",paramO);
		}

		IPCServer.I=null
		IPCServer.__init$=function(){
			;
			IPCServer.I=new IPCServer();
		}

		return IPCServer;
	})()


	/**
	*...
	*@author ww
	*/
	//class debugviewkit.servertools.RemoteWorkUtils
	var RemoteWorkUtils=(function(){
		function RemoteWorkUtils(){}
		__class(RemoteWorkUtils,'debugviewkit.servertools.RemoteWorkUtils');
		RemoteWorkUtils.walkTargetEX=function(target,fun,_this,filterFun,parent){
			if (filterFun !=null && !filterFun(target))return;
			fun.apply(_this,[target,parent]);
			var i=0;
			var len=0;
			var tChild;
			var childs;
			childs=target._childs || target._children;
			if (childs){
				len=childs.length;
				for(i=0;i<len;i++){
					tChild=childs[i];
					RemoteWorkUtils.walkTargetEX(tChild,fun,_this,filterFun,target);
				}
			}
			childs=target._components;
			if (childs){
				len=childs.length;
				for(i=0;i<len;i++){
					tChild=childs[i];
					RemoteWorkUtils.walkTargetEX(tChild,fun,_this,filterFun,target);
				}
			}
		}

		RemoteWorkUtils.findNodeByGid=function(gid){
			if (RemoteWorkUtils._gidDic[gid])return RemoteWorkUtils._gidDic[gid];
			var item;
			function workChild (child){
				RemoteWorkUtils._gidDic[IDTools.getObjIDAuto(child)]=child;
				if (IDTools.getObjIDAuto(child)==gid){
					item=child;
				}
			}
			RemoteWorkUtils.walkTargetEX(Laya.stage,workChild,null,null);
			return item;
		}

		RemoteWorkUtils.findNodeByCompId=function(compId,rootGid){
			(rootGid===void 0)&& (rootGid=-1);
			var root;
			if (rootGid){
				root=RemoteWorkUtils.findNodeByGid(rootGid);
			}
			if (!root)root=Laya.stage;
			var item;
			function workChild (child){
				RemoteWorkUtils._gidDic[child.compId]=child;
				if (child.compId==compId){
					item=child;
				}
			}
			RemoteWorkUtils.walkTargetEX(root,workChild,null,null);
			return item;
		}

		RemoteWorkUtils.updateNodeProp=function(node,props){
			var key;
			for (key in props){
				node[key]=props[key];
			}
		}

		RemoteWorkUtils.updateNodePropByGid=function(gid,props){
			var node;
			node=RemoteWorkUtils.findNodeByGid(gid);
			if (node){
				RemoteWorkUtils.updateNodeProp(node,props);
			}
		}

		RemoteWorkUtils.getAllTargetView=function(){
			var viewList;
			viewList=[];
			function workChild (child){
				if (child["__$fileRefer"]){
					var obj;
					obj={};
					obj.path=child["__$fileRefer"];
					obj.gid=IDTools.getObjIDAuto(child);
					obj.compId=child.compId;
					viewList.push(obj);
				}
			}
			RemoteWorkUtils.walkTargetEX(Laya.stage,workChild,null,null);
			return viewList;
		}

		RemoteWorkUtils.getAdptPropValue=function(value,propConfig){
			if (propConfig&&value){
				switch(propConfig.type){
					case "vec":
						if (! (value instanceof Array)){
							value=[value.x,value.y];
						}
						break ;
					}
			}
			return value;
		}

		RemoteWorkUtils.getObjectDataWithKeys=function(data,keys){
			var i=0,len=0;
			len=keys.length;
			var propsO;
			propsO={};
			for (i=0;i < len;i++){
				/*no*/this.key=keys[i].name;
				propsO[/*no*/this.key]=RemoteWorkUtils.getAdptPropValue(data[/*no*/this.key],keys[i]);
			};
			var dataO;
			dataO=RemoteWorkUtils.createNodeDataOByNode(data);
			dataO.hasKeys=true;
			dataO.props=propsO;
			return dataO;
		}

		RemoteWorkUtils.getObjectData=function(data,keys){
			if (!data)return null;
			var dataList;
			var tData;
			var key;
			var tValue;
			var tType;
			dataList=[];
			if (!keys){
				keys=ClassTool.getObjectDisplayAbleKeys(data,[]);
				keys.sort();
			};
			var i=0,len=0;
			len=keys.length;
			for (i=0;i < len;i++){
				key=keys[i];
				tValue=data[key];
				tType=typeof(tValue);
				if (key.charAt(0)=="_")
					continue ;
				if (RemoteWorkUtils.displayTypes[tType]){
					tData={};
					tData["key"]=key;
					tData["value"]=tValue;
					tData["type"]=tType;
					dataList.push(tData);
				}
			};
			var dataO;
			dataO=RemoteWorkUtils.createNodeDataOByNode(data);
			dataO.props=dataList;
			return dataO;
		}

		RemoteWorkUtils.changeObjectValue=function(gid,key,value){
			var node;
			node=RemoteWorkUtils.findNodeByGid(gid);
			if (node){
				node[key]=value;
			}
		}

		RemoteWorkUtils.getObjectDataByGid=function(gid){
			return RemoteWorkUtils.getObjectData(RemoteWorkUtils.findNodeByGid(gid));
		}

		RemoteWorkUtils.getObjectDataByDataO=function(dataO){
			if (dataO.keys){
				return RemoteWorkUtils.getObjectDataWithKeys(RemoteWorkUtils.findNodeByGid(dataO.compId),dataO.keys);
			}
			return RemoteWorkUtils.getObjectDataByGid(dataO.compId);
		}

		RemoteWorkUtils.createNodeDataOByNode=function(child){
			var obj;
			obj={};
			obj.gid=IDTools.getObjIDAuto(child);
			obj.compId=IDTools.getObjIDAuto(child);
			obj.id=child.compId;
			obj.name=child.name;
			obj.type=ClassTool.getClassName(child);
			obj.label=ClassTool.getNodeClassAndName(child);
			obj.child=[];
			return obj;
		}

		RemoteWorkUtils.getTree=function(){
			var nodeDic={};
			function getNode (gid,child){
				if (!nodeDic[gid]){
					var obj;
					obj={};
					obj.gid=IDTools.getObjIDAuto(child);
					obj.compId=IDTools.getObjIDAuto(child);
					obj.id=child.compId;
					obj.name=child.name;
					obj.type=ClassTool.getClassName(child);
					obj.label=ClassTool.getNodeClassAndName(child);
					obj.visible=child.visible;
					obj.child=[];
					nodeDic[gid]=obj;
				}
				return nodeDic[gid];
			}
			function getNodeOByNode (node){
				if (!node)return null;
				return getNode(IDTools.getObjIDAuto(node),node);
			}
			function workChild (child,parent){
				var gid=0;
				gid=IDTools.getObjIDAuto(child);
				var obj;
				obj=getNodeOByNode(child);
				var parentO;
				parentO=getNodeOByNode(parent);
				if (parentO){
					parentO.child.push(obj);
				}
			}
			RemoteWorkUtils.walkTargetEX(Laya.stage,workChild,null,null);
			return getNodeOByNode(Laya.stage);
		}

		RemoteWorkUtils.showTargetBounds=function(gid){
			var node;
			node=RemoteWorkUtils.findNodeByGid(gid);
			if (node){
				DisTool.showDisBounds(node);
			}
		}

		RemoteWorkUtils.ViewSign="__$fileRefer";
		RemoteWorkUtils._gidDic={};
		__static(RemoteWorkUtils,
		['displayTypes',function(){return this.displayTypes={"boolean":true,"number":true,"string":true };}
		]);
		return RemoteWorkUtils;
	})()


	Laya.__init([IPCServer]);
})(window,document,Laya);
